package com.project.controller;

import com.project.bean.OutboundBean;
import com.project.bean.UserBean;
import com.project.service.IOutboundService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequiresPermissions("outbound")
@RequestMapping("outbound")
public class OutboundController {
    @Autowired
    private IOutboundService outboundService;
    @RequestMapping("findById")//根据销售员姓名（登录用户的session）查询销售车商品集合，同时查询商品名称、品牌、建议销售价、库存数量
    public List<OutboundBean> findById(HttpServletRequest request) {//
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");//得到当前登录用户的对象
        return outboundService.findById(user.getName());
    }
    @RequestMapping("add")
    public String add(String stockId,HttpServletRequest request) { // 将需要出库的商品添加到销售车
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");//得到当前登录用户的对象
        outboundService.add(stockId,user.getName());
        return "ok";
    }
    @RequestMapping("remove")
    public String remove(Integer id) {//移除销售车中的商品
        outboundService.remove(id);
        return "ok";
    }
    @RequestMapping("updateNum")
    public String updateNum(Integer id, Integer newNum) {//修改销售商品的数量
        outboundService.updateNum(id,newNum);
        return "ok";
    }

}
